package com.inibb.app.util.upload;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import com.inibb.app.util.io.FileUtil;



public class VirusScanHandler implements FileHandler {
	private Properties fileConfig;
	
	
	public VirusScanHandler(Properties fileConfig) {
		super();
		this.fileConfig = fileConfig;
	}


	public ValidationResult handle(File file){
		
		 ValidationResult vr=new ValidationResult();
		try {
			
			Boolean result=FileUtil.checkVirus(new FileInputStream(file), fileConfig.getProperty("system.upload.virusScanFolder"));
			if(!result){
				vr.getErrors().put(file.getName(), "The file have virus!");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return vr;
	}
	
	
	public static void main(String[] args) {
		File file=new File("d:/fileupload.properties");
		Properties config=new Properties();
		config.setProperty("system.upload.virusScanFolder", "d:/virus");
		ValidationResult result=new VirusScanHandler(config).handle(file);
		System.out.println(result.getErrors().get(file.getName()));
	}

}
